/* ipumap.h --
 * Copyright 2009  cwxstat LLC., Elkins Park, Pennsylvania.
 * All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Authors:
 *     Mike Chirico <mchirico@gmail.com>
 *     
 */
#include <string>
#include <map>

class StringTokenizer
{

      public:

	StringTokenizer(const char *s, const char *delim = NULL);
	 ~StringTokenizer();

	size_t countTokens();
	bool hasMoreTokens();

	void nextToken(std::string & s);

      private:
	  StringTokenizer()
	{
	};
	std::string delim_;
	std::string str_;
	int count_;
	size_t begin_;
	size_t end_;
};

class IPUmap
{

      public:
	typedef std::map < std::string, long, std::less < std::string > >H;
	typedef std::map < std::string, long, std::less < std::string > >*Hp;

	  IPUmap(const char *s);

	 ~IPUmap();

	bool check(const char *ip, const char *user);
	void succlogin(const char *ip, const char *acct);
	void prw();
	void pr();

      private:

	void hpadd(Hp hp, std::string * ipu);

	long hpadd(Hp hp, const char *s);

	long _validate(Hp hp, std::string ipu);

	long validate(Hp hp, std::string s);

	long validate(Hp hp, const char *s);

	long validate(Hp hp, const char *ip, const char *acct);

	long _reset(Hp hp, std::string ipu);

	long reset(Hp hp, const char *ip, const char *acct);
	long reset(Hp hp, std::string s);
	long _whiteadd(Hp hp, std::string ipu);
	long whiteadd(Hp hp, const char *s);
	long whiteadd(Hp hp, std::string s);

      private:

        Hp white;
	Hp database;
	StringTokenizer st;
};
